let SetmaximizButtonName=function (state) {
    let maximizButtonElms = document.getElementsByClassName("use-webapp-window-maximiz-button");
    if (state == WindowState.Maximized) {
        for (let i = 0; i < maximizButtonElms.length; i++) {
            maximizButtonElms[i].innerText = "恢复";
        }
    }
    else {
        for (let i = 0; i < maximizButtonElms.length; i++) {
            maximizButtonElms[i].innerText = "最大化";
        }
    }
}
function WriteErrorMessage(msg) {
    let out = document.getElementById("OutTestMsg");
    if (msg.indexOf("false") != -1) {
        out.innerHTML += "<span style='color:red'>" + msg + "</span>" + "<br/>";
    }
    else {
        out.innerHTML += msg + "<br/>";
    }
}
let testService;
async function Main() {
    ThisWindow.AddEventListener("WindowStateChanged", SetmaximizButtonName);
    testService = new TestService();
}
async function devTest() {
    //for (let i = 0; i < 100; i++) {
    //    let r = await testService.DevFunc((msg: string): string => {
    //        WriteErrorMessage(msg);
    //        return msg;
    //    }, "Js 回传");
    //}
    let r = await testService.DevFunc((msg) => {
        WriteErrorMessage(msg);
        return msg;
    }, "Js 回传");
}
async function test() {
    let out = document.getElementById("OutTestMsg");
    out.innerHTML = "";
    //NullTest
    WriteErrorMessage("ListTest");
    let sayNameInfo1 = new SayNameInfo();
    sayNameInfo1.Index = 1;
    sayNameInfo1.Name = "Esrin测试1";
    sayNameInfo1.Parent = null;
    sayNameInfo1.SubList = null;
    let sayNameInfo2 = new SayNameInfo();
    sayNameInfo2.Index = 2;
    sayNameInfo2.Name = "Esrin测试2";
    sayNameInfo2.Parent = null;
    sayNameInfo2.SubList = null;
    let sayNameInfo3 = new SayNameInfo();
    sayNameInfo3.Index = 3;
    sayNameInfo3.Name = "Esrin测试3";
    sayNameInfo3.Parent = null;
    sayNameInfo3.SubList = null;
    let sayNameInfo4 = new SayNameInfo();
    sayNameInfo4.Index = 4;
    sayNameInfo4.Name = "Esrin测试4";
    sayNameInfo4.Parent = null;
    sayNameInfo4.SubList = null;
    sayNameInfo1.Parent = sayNameInfo4;
    sayNameInfo1.SubList = new Array();
    sayNameInfo1.SubList.push(sayNameInfo2);
    sayNameInfo2.SubList = new Array();
    sayNameInfo2.SubList.push(sayNameInfo3);
    let inList = new Array();
    let list1 = new Array();
    let list2 = new Array();
    let list3 = new Array();
    inList.push(list1);
    inList.push(list2);
    inList.push(list3);
    list1.push(sayNameInfo2);
    list1.push(sayNameInfo3);
    list2.push(sayNameInfo1);
    list2.push(sayNameInfo4);
    list3.push(sayNameInfo2);
    let rlist = await testService.ListTest(true, inList, "Js ListTest测试");
    WriteErrorMessage((JSON.stringify(rlist) == JSON.stringify(inList)).toString());
    WriteErrorMessage("ListTest end");
    //ArrayTest
    WriteErrorMessage("ArrayTest");
    let rarray = await testService.ArrayTest(100, list2, "Js ArrayTest测试");
    WriteErrorMessage((JSON.stringify(rarray) == JSON.stringify(list2)).toString());
    WriteErrorMessage("ArrayTest end");
    //NoneTest
    //NullTest
    WriteErrorMessage("NullTest");
    let NullTestResult = await testService.NullTest(null);
    WriteErrorMessage((NullTestResult === null).toString());
    WriteErrorMessage("NullTest end");
    //NoneTest
    WriteErrorMessage("NoneTest");
    await testService.NoneTest();
    WriteErrorMessage("NoneTest end");
    //NoneStringTest
    WriteErrorMessage("NoneStringTest");
    let rNoneStringTest = await testService.NoneStringTest("");
    WriteErrorMessage((rNoneStringTest === "").toString());
    WriteErrorMessage("NoneStringTest end");
    //EntityTest
    WriteErrorMessage("EntityTest");
    let entity = await testService.EntityTest(100, sayNameInfo1, 200);
    WriteErrorMessage((JSON.stringify(sayNameInfo1) == JSON.stringify(entity)).toString());
    WriteErrorMessage("EntityTest end");
    //BaseTest
    WriteErrorMessage("BaseTest");
    let BaseTestResult = await testService.BaseTest(-200, 200, -300, 300, true, 255, false, -120, 1.2, 1.3, "BaseTest测试");
    WriteErrorMessage("1.2:" + BaseTestResult);
    WriteErrorMessage("BaseTest end");
    //FuncTest
    WriteErrorMessage("FuncTest");
    let len = 10;
    let bytes = new Uint8Array(len);
    for (let i = 0; i < len; i++) {
        bytes[i] += 12;
    }
    let position = { Offset: 0 };
    let innerVal = "this main";
    let r = await testService.FuncTest((msg) => {
        WriteErrorMessage(innerVal + ":" + msg + ":" + msg.length);
        return msg;
    }, bytes, "FuncTest 回传参数");
    WriteErrorMessage((r.length === len) + ":" + (JSON.stringify(r) === JSON.stringify(bytes)));
    WriteErrorMessage("FuncTest end");
    //FuncTest2
    WriteErrorMessage("FuncTest2");
    r = await testService.FuncTest2(() => {
        WriteErrorMessage(innerVal);
        return "js FuncTest2 回传";
    }, bytes, "FuncTest2 回传参数");
    WriteErrorMessage((r.length === len) + ":" + (JSON.stringify(r) === JSON.stringify(bytes)));
    WriteErrorMessage("FuncTest2 end");
    //ActionTest
    WriteErrorMessage("ActionTest");
    r = await testService.ActionTest((a, b, x, y, b1, be, b2, sbe, d, f, str) => {
        WriteErrorMessage((a != -200 || b != 200 || x != -300 || y != 300 || b1 != true || be != 255 || b2 != false || sbe != -120 || d != 1.2 || f != 1.3 || str != "ActionTest测试").toString());
    }, "ActionTest测试", bytes);
    WriteErrorMessage((r.length === len) + ":" + (JSON.stringify(r) === JSON.stringify(bytes)));
    WriteErrorMessage("ActionTest end");
    //ActionTest2
    WriteErrorMessage("ActionTest2");
    r = await testService.ActionTest2(() => {
        WriteErrorMessage("js ActionTest2 输出");
    }, "ActionTest2测试", bytes);
    WriteErrorMessage((r.length === len) + ":" + (JSON.stringify(r) === JSON.stringify(bytes)));
    WriteErrorMessage("ActionTest2 end");
    WriteErrorMessage("all test is end");
}